/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.agenda.model;

import com.agenda.model.entity.AmTbMedi;
import com.agenda.model.persistence.DAOFactory;
import com.agenda.model.repository.MedicoRepository;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.Stateless;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Ronildo
 */

@Stateless
@WebService(serviceName = "MedicoBOImpl")
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT)
public class MedicoBOImpl implements MedicoBO{
    
    
    @PersistenceContext
    private EntityManager em;
    private MedicoRepository medicoRepository;
    
    @PostConstruct
    public void initialize(){
        medicoRepository = DAOFactory.getMedicoRepository(em);
    }
    
    @WebMethod
    public void insertMedico(@WebParam(name = "medico")AmTbMedi medico){
        medicoRepository.persist(medico); 
    }
    
    @WebMethod
    public void deleteMedico(@WebParam(name = "medico")AmTbMedi medico){
        medicoRepository.remove(medico, medico.getNrCrm());
    }
    
    @WebMethod
    public void updateMedico(@WebParam(name = "medico")AmTbMedi medico){
        medicoRepository.update(medico);
    }
    
    @WebMethod
    public AmTbMedi findMedicoById(@WebParam(name = "id")Long id){
        return medicoRepository.findById(id);
    }
    
    @WebMethod
    public List<AmTbMedi> listMedico(@WebParam(name = "medico")AmTbMedi medico){
        return medicoRepository.list(medico);
    }
    
}
